<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {optionsAction} from '@/api/statistics'
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null,
      datas:{}
    }
  },
  watch: {
  },
  mounted() {
    this.$nextTick(() => {
      this.initData()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initData(){
      optionsAction("order").then(response=>{
        this.datas =  response.data;
      }).finally(()=>{
         this.initChart()
      })
    },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },
    setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        color:['#5470c6','#9a60b4','#ee6666','#3ba272','#73c0de','#91cc75', '#fac858', '#fc8452', '#ea7ccc'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          legend: {},
          grid: {
            left: '1%',
            right: '1%',
            bottom: '1%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
              data:this.datas.xData
            }
          ],
          yAxis: [
            {
              type: 'value'
            }
          ],
          series: [
            {
              name: '入库',
              type: 'bar',
              emphasis: {
                focus: 'series'
              },
              // data: [320, 332, 301, 334, 390, 330, 320, 332, 301, 334, 390, 330]
              data:this.datas.yData.warehouseNums
            },
            {
              name: '移交出库',
              type: 'bar',
              stack: 'Ad',
              emphasis: {
                focus: 'series'
              },
              // data: [120, 132, 101, 134, 90, 230, 210, 132, 101, 134, 90, 230]
              data:this.datas.yData.exWarehouseNums
            },
            {
              name: '调用出库',
              type: 'bar',
              stack: 'Ad',
              emphasis: {
                focus: 'series'
              },
              // data: [220, 182, 191, 234, 290, 330, 310, 182, 191, 234, 290, 330]
              data:this.datas.yData.transferNums
            },
            {
              name: '处置出库',
              type: 'bar',
              stack: 'Ad',
              emphasis: {
                focus: 'series'
              },
              // data: [150, 232, 201, 154, 190, 330, 410, 232, 201, 154, 190, 330]
              data:this.datas.yData.dealNums
            },
            {
              name: '物品数量',
              type: 'bar',
              // data: [862, 1018, 964, 1026, 1679, 1600, 1570, 1018, 964, 1026, 1679, 1600],
              data:this.datas.yData.nums,
              emphasis: {
                focus: 'series'
              },
              markLine: {
                lineStyle: {
                  type: 'dashed'
                },
                data: [[{ type: 'min' }, { type: 'max' }]]
              }
            }
            // {
            //   name: '货币',
            //   type: 'bar',
            //   barWidth: 5,
            //   stack: '物品数量',
            //   emphasis: {
            //     focus: 'series'
            //   },
            //   data: [620, 732, 701, 734, 1090, 1130, 1120, 732, 701, 734, 1090, 1130]
            // },
            // {
            //   name: '交通工具',
            //   type: 'bar',
            //   stack: '物品数量',
            //   emphasis: {
            //     focus: 'series'
            //   },
            //   data: [120, 132, 101, 134, 290, 230, 220, 132, 101, 134, 290, 230]
            // },
            // {
            //   name: '违禁品',
            //   type: 'bar',
            //   stack: '物品数量',
            //   emphasis: {
            //     focus: 'series'
            //   },
            //   data: [60, 72, 71, 74, 190, 130, 110, 72, 71, 74, 190, 130]
            // },
            // {
            //   name: '贵重物品',
            //   type: 'bar',
            //   stack: '物品数量',
            //   emphasis: {
            //     focus: 'series'
            //   },
            //   data: [62, 82, 91, 84, 109, 110, 120, 82, 91, 84, 109, 110]
            // }
          ]
      })
    }
  }
}
</script>
